package com.example.smartcity.logic.utils

import android.content.Context
import android.view.MotionEvent
import android.widget.ScrollView
import com.example.smartcity.SmartCityApplication.Companion.context
import kotlin.math.abs

class MIXScrollView(context: Context) : ScrollView(context){
    var lastX: Int? = null
    var lastY: Int? = null

    override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
        var ss =  super.onInterceptTouchEvent(ev)

        when(ev?.action){
            MotionEvent.ACTION_DOWN -> {
                lastX = ev.x.toInt()
                lastY = ev.y.toInt()
            }

            MotionEvent.ACTION_MOVE -> {
                val slopX = abs(ev.x - lastX!!)
                val slopY = abs(ev.y - lastY!!)
                if((slopY > 0 || slopY > 0) && slopX <= slopY){
                    requestDisallowInterceptTouchEvent(true)
                    ss = true
                } else {
                    ss = false
                }
            }

            MotionEvent.ACTION_UP -> ss = false
        }
        return ss
    }
}